|
|
|
|
|
|
|
The constant will differ depending on the control to which youre sending the message and what you want that control to do. The last two parameters will also differ depending on the control and the specific message youre sending. In this case, the -1 value tells the list box to begin LB_FINDSTRING at the beginning of the list. The last parameter tells the list box what to find. This string parameter must be prefaced by the ByVal keyword. |
|
|
|
|
|
|
|
|
You can also use very similar code to search for a value in a combo box. However, the second parameter would be CB_FINDSTRING instead of LB_FINDSTRING. |
|
|
|
|
|
|
|
|
If you were to write your own searching routine in Visual Basic, it would look like the following: |
|
|
|
 |
|
|
|
|
Sub ListSearch (ctrName As Control, strFindStr As String)
'Search For String
Dim intLoop As Integer
Dim strValue As String
For intLoop = 0 To ctrName.ListCount - 1
strValue = ctrName.List(intLoop)
If Trim$(UCase$(strValue)) = _
Trim$(UCase$(strFindStr)) Then
ctrName.ListIndex = intLoop
intLoop = ctrName.ListCount ' Force Exit From Loop
Else
ctrName.ListIndex = -1
End If
Next intLoop
End Sub |
|
|
|
 |
|
|
|
|
TIP Its much more efficient to use the SendMessage() API to search for a value in a list box than to write your own code in Visual Basic. |
|
|
|
|
|
|
|
|
The standard list box that comes with Visual Basic does not have a property that allows you to create columns in the list box. However, using the Windows API call SendMessage(), you can add tab stops to a list box. This comes in really handy when youre using a proportional font that would otherwise make it impossible to line up columns of data. |
|
|
|
|
|